from typing import Generator

from playwright.sync_api import BrowserContext, Page, expect
import pytest

import actions.colocation.colocation_overview as co

pytest.mark.usefixtures("login_and_store_state")


@pytest.fixture(scope='function', autouse=True)
def overview_page(context: BrowserContext) -> Generator[Page, None, None]:
    page = context.new_page()
    co.visit_colocation_overview_page(page) 
    yield page
    page.close()


class TestSideMenu:
    """
    @description 测试混部相关的侧边栏功能点，包括：
    - 各跳转链接的正确性
    """
    @staticmethod
    def test_should_have_colocation_links(overview_page: Page):
        """Test 35"""
        expect(co.get_sidemenu_link_overview(overview_page)).to_be_visible()
        expect(co.get_sidemenu_link_configuration(overview_page)).to_be_visible()
        expect(co.get_sidemenu_link_monitor(overview_page)).to_be_visible()

        co.get_sidemenu_link_configuration(overview_page).click()
        expect(overview_page).to_have_url('/container_platform/colocation/ColocationConfiguration')

        co.get_sidemenu_link_monitor(overview_page).click()
        expect(overview_page).to_have_url('/container_platform/colocation/ColocationMonitor')

        co.get_sidemenu_link_overview(overview_page).click()
        expect(overview_page).to_have_url('/container_platform/colocation/ColocationOverview')


class TestColocationOverviewPage:
    """
    @description 测试混部概览页面的主要功能点，包括：
    - 信息抽屉的打开/关闭功能
    - 页面跳转链接的正确性
    """
    @staticmethod
    def test_open_close_drawer_by_clicking_question_marks_part_1(overview_page: Page):
        """Test 37"""
        co.do_click_info_1(overview_page)
        expect(co.get_drawer_title_1(overview_page)).to_be_visible()
        co.do_close_drawer(overview_page)
        expect(co.get_drawer_title_1(overview_page)).not_to_be_visible()

    @staticmethod
    def test_open_close_drawer_by_clicking_question_marks_part_3(overview_page: Page):
        """Test 38"""
        co.do_click_info_3(overview_page)
        expect(co.get_drawer_title_3(overview_page)).to_be_visible()
        co.do_close_drawer(overview_page)
        expect(co.get_drawer_title_3(overview_page)).not_to_be_visible()

    @staticmethod
    def test_link_to_colocation_confifuration_page(overview_page: Page):
        """Test 39"""
        co.do_click_link_2(overview_page)
        expect(overview_page).to_have_url('/container_platform/colocation/ColocationConfiguration')

    @staticmethod
    def test_link_to_deployment_page(overview_page: Page):
        """Test 40"""
        co.do_click_link_3(overview_page)
        expect(overview_page).to_have_url('/container_platform/workload/pod')

    @staticmethod
    def test_link_to_colocation_monitor_page(overview_page: Page):
        """Test 41"""
        co.do_click_link_4(overview_page)
        expect(overview_page).to_have_url('/container_platform/colocation/ColocationMonitor')